Executes the specified query.
Syntax
Parameters
- query
Type Parameters
- T
- Return type
Return Value
A collection of
T
Example
C# | Copy Code |
---|
public void ExecuteQuerySamples() {
DomainModelEntityManager mgr = new DomainModelEntityManager();
// 1a) Query by type
EntityQuery<Customer> query1a = mgr.Customers;
IEnumerable<Customer> results1a = mgr.ExecuteQuery<Customer>(query1a);
// 1b) Query by type with a query strategy
EntityQuery<Customer> query1b = mgr.Customers.With(QueryStrategy.CacheOnly);
IEnumerable<Customer> results1b = mgr.ExecuteQuery<Customer>(query1b);
// 1c) Query by type using immediate execution
List<Customer> results1c = mgr.Customers.ToList();
// 2a) Query by EntityKey
EntityKey key = new EntityKey(typeof(Customer), "ALFKI");
var customer2a = key.ToQuery().FirstOrNullEntity();
// 2b) Query by EntityKey with a query strategy
var customer2b = key.ToQuery().With(QueryStrategy.CacheOnly).FirstOrNullEntity();
// 3a) Query by a list of EntityKeys
EntityKeyList keys = new EntityKeyList(typeof(Customer));
keys.Add(new EntityKey(typeof(Customer), "ALFKI"));
keys.Add(new EntityKey(typeof(Customer), "BONAP"));
EntityKeyQuery query3a = keys.ToQuery();
var results3a = mgr.ExecuteQuery(query3a);
// 3b) Query by a list of EntityKeys with query strategy
var results3b = mgr.ExecuteQuery(query3a.With(QueryStrategy.CacheOnly));
// 4a) Query with an EntityQuery
IEntityQuery<Customer> q4 = mgr.Customers.Where(c => c.CustomerID.StartsWith("A"));
IEnumerable<Customer> results4a = mgr.ExecuteQuery<Customer>(q4);
// 4b) Query with an EntityQuery and query strategy
IEnumerable<Customer> results4b = mgr.ExecuteQuery<Customer>(q4.With(QueryStrategy.CacheOnly));
} |
Remarks
Requirements
Target Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family
See Also